package com.zx.service.impl;

import com.alibaba.fastjson.JSON;
import com.zx.entity.Product;
import com.zx.mapper.ProductMapper;
import com.zx.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020-03-11
 */
@Slf4j
@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public Product findById(Long id) {
        log.info("查询商品信息：商品id{}",id);
        Product product = productMapper.findById(id).get();
        log.info("查询商品完成，商品内容：{}", JSON.toJSONString(product));
        return product;
    }

    @Override
    public Product addProduct(Product product) {
        return productMapper.save(product);
    }

    @Override
    public Product updateProduct(Product product) {
        return productMapper.save(product);
    }

    @Override
    public void deleteById(Long id) {
        productMapper.deleteById(id);
    }
}
